package com.csmall.order.webapi.controller;

import com.csmall.commons.pojo.order.dto.OrderAddDTO;
import com.csmall.commons.pojo.order.entity.Order;
import com.csmall.commons.restful.JsonPage;
import com.csmall.commons.restful.JsonResult;
import com.csmall.order.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Name: OrderController
 * @Author: 西风残叶
 * @Date: 2024/8/18 18:36
 * @Version: 1.0
 * @TODO: TODO
 */
@RestController
@RequestMapping("/base/order")
@Api(tags = "订单管理模块")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/add")
    @ApiOperation("新增订单的功能")
    public JsonResult orderAdd(OrderAddDTO orderAddDTO){
        orderService.orderAdd(orderAddDTO);
        return JsonResult.ok("新增订单完成");
    }
    
    @GetMapping("/page")
    @ApiOperation("分页查询所有订单")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码",name = "page",example = "1"),
            @ApiImplicitParam(value = "每页数据",name="pageSize",example = "10")
    })
    public JsonResult<JsonPage<Order>> pageOrder(Integer page, Integer pageSize){
        JsonPage<Order> allOrdersByPage = orderService.getAllOrdersByPage(page, pageSize);
        return JsonResult.ok("查询完成!",allOrdersByPage);
    }
}